
using System;
using Gnome;
using Gdk;

namespace DiaCanvas
{
	public class Rombo:Figura
	{
		protected int _x;
		protected int _y;
		private int _height;
		private int _width;
		
		private Gnome.CanvasPolygon _fig;
		
		private string _color;
		private string _color2;
		
		private bool _bDrag;
		
		private Gdk.Point _oldPoint;
		
		override protected Gnome.CanvasShape Shape { get { return this._fig; }}
		
		public Rombo(Gdk.Point p, int w, int h, Gnome.Canvas c): base(c)
		{
			Console.WriteLine("Rombo");
			this._point = p;
			this._height = h;
			this._width = w;

			CalculateControlPoints();
		}
		
		protected override void CalculateControlPoints()
		{
			int z = 10;
		
			this._points = new Gdk.Point[4];
			this._points.SetValue( new Point( this._point.X - this._width / 2 +z ,this._point.Y ),0);
			this._points.SetValue( new Point(this._point.X  ,this._point.Y - this._height/2  + z),1);
			this._points.SetValue( new Point(this._point.X + this._width / 2 -z ,this._point.Y ),2);
			this._points.SetValue( new Point(this._point.X ,this._point.Y + this._height/2 -z ),3);
		}
		
		override protected void Resize(Object obj, EventButton ev)
		{
			double dx = ev.X - this._oldPoint.X;
			double dy = ev.Y - this._oldPoint.Y;
			
					
		}
		
		
		override public string toString()
		{
			return "Este es un rombo";
		}
		
		public override FiguraType Type
		{
			get 
			{
				return FiguraType.Rombo;
			}
		}
		
		override public void draw()
		{
			Write("Dibujando el Rombo"); 
			
			this._fig = new Gnome.CanvasPolygon(this._canvas.Root());
			
	        this._fig.Points = new CanvasPoints (new double[]{this._point.X-this._width/2,this._point.Y, this._point.X,
            								this._point.Y-this._height/2, this._point.X+this._width/2,this._point.Y,
            								this._point.X,this._point.Y+this._height/2});
			
					
			this._fig.CanvasEvent += new Gnome.CanvasEventHandler(CanvasEvent);
						
			this._fig.OutlineColor = this.ForeColor;
			this._fig.FillColor = this.BackColor;
       		this._fig.WidthPixels = 1;
       		this._fig.Show();
			
			DrawControlPoints();
			
		}
		
		public void CanvasEvent(object obj, Gnome.CanvasEventArgs args)
		{
			
			EventButton ev = new EventButton (args.Event.Handle);
			switch (ev.Type) 
			{
				case EventType.MotionNotify:
					if ( this._bDrag )
					{
						Move(ev);
					}
					break;
					
				case EventType.EnterNotify:
					MouseEnter(obj,args);
					break;
	
					
				case EventType.LeaveNotify:
					MouseLeave(obj,args);
					break;
	
				case EventType.DragEnter:

					break;
					
				case EventType.ButtonPress:
					if ( this._bIn )
					{
						this._bDrag = true;
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.ButtonRelease:
					if ( this._bDrag )
					{
						Move(ev);
					}
					this._bDrag = false;
					break;
			}
			
		}
		
		protected override void ChangeColor()
		{
			
			
		}
		
	}
}
